package com.woniu.service.impl;

import com.woniu.entity.Address;
import com.woniu.entity.Useraddress;
import com.woniu.mapper.AddressMapper;
import com.woniu.mapper.UseraddressMapper;
import com.woniu.service.UserAddressService;
import com.woniu.util.ResponseEnum;
import com.woniu.util.ResponseUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class UserAddressServiceImpl implements UserAddressService {
    @Resource
    private UseraddressMapper useraddressMapper;
    @Resource
    private AddressMapper addressMapper;
    @Override
    public ResponseUtil addUserAddress( Address record) {
        int i = addressMapper.add(record);
        return ResponseUtil.get(i > 0 ? ResponseEnum.OK : ResponseEnum.FAIL);
    }

    @Override
    public ResponseUtil findUserAddress(Integer userId) {
        List<Address> list = addressMapper.findByUserId(userId);
        return ResponseUtil.get(list != null ? ResponseEnum.OK : ResponseEnum.FAIL, list);
    }

    @Override
    public ResponseUtil updateUserAddress(Address useraddress) {
        int i = addressMapper.update(useraddress);
        return ResponseUtil.get(i > 0 ? ResponseEnum.OK : ResponseEnum.FAIL);
    }

    @Override
    public ResponseUtil deleteUserAddress(Integer addressId) {
        int i = addressMapper.delete(addressId);
        return ResponseUtil.get(i > 0 ? ResponseEnum.OK : ResponseEnum.FAIL);
    }
}
